/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.himilco.ocana.workflow.core.dao;

import com.himilco.ocana.workflow.core.dao.entities.Incident;
import com.himilco.ocana.workflow.core.dao.entities.Ticket;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author oussema
 */
public class OperatorDAL {

    private EntityManager em;

    public OperatorDAL(EntityManager entityManager) {
        this.em = entityManager;
    }

    public OperatorDAL() {
    }

    public void lazyFindTickets(){
    
    }
    public List<Ticket> findAll() {
//        initDb();
        javax.persistence.Query query = em.createQuery("SELECT i FROM db_ocana_ticket i where status='OPEN'");
        List<Ticket> results = query.getResultList();
        System.out.println("Nbr Tickets DAL Operator: " + results.size());
        return results;
    }

    public void updateTicket(Ticket t) {
        em.merge(t);
    }

    public void initDb() {
        Ticket ticket1 = new Ticket();
        Incident incident1 = new Incident("CASH PROBLEM", "IMPORTANT", "IMPORTANT", "IMPORTANT", "1H", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT", "IMPORTANT");
        ticket1.setStartTime(new Date());
        ticket1.setStatus("OPEN");
        ticket1.setIncident(incident1);
        em.persist(incident1);
        em.persist(ticket1);

        Ticket ticket2 = new Ticket();
        Incident incident2 = new Incident("KEY BOARD PROBLEM", "IMPORTANT", "TOTO", "TOTO", "30MN", "TOTO", "TOTO", "TOTO", "TOTO", "TOTO", "TOTO", "TOTO", "TOTO", "TOTO");
        ticket2.setStartTime(new Date());
        ticket2.setStatus("MANUAL_INTERVENTION");
        ticket2.setIncident(incident2);


        em.persist(incident2);
        em.persist(ticket2);
        ticket2.setStatus("SERVICE_NOTIFIED");
        em.persist(ticket2);
    }
}
